package Server;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

	public static void main(String[] args){
		try {
			ServerSocket ss = new ServerSocket(8080);

			while(true){
				Socket client = ss.accept();
				System.out.println("accepted");

				BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
				BufferedReader bf = new BufferedReader(new InputStreamReader(client.getInputStream()));

				String user = bf.readLine();

				while(user != null && !user.equals("END")){
					System.out.println(user);
					bw.write(user);
					user = bf.readLine();
				}
				bw.flush();
				bw.close();
			}
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}
}
